﻿using System;
using System.Collections.Generic;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class DAOHocSinh
    {

        public static DataTable LietKeLookupEditData(string nameproc)
        {
            try
            {
                DataTable kq = SQLDataProvider.ExecuteQuery(nameproc);
                return kq;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable DanhSachHocSinh()
        {
            try
            {
                DataTable dt = SQLDataProvider.ExecuteQuery("sp_LietKeThongTinHocSinh");
                DataColumn columnChon = new DataColumn("IsCheck", System.Type.GetType("System.Boolean"));
                columnChon.DefaultValue = false;
                dt.Columns.Add(columnChon);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int ThemHocSinh(DTOHocSinh hocsinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@HOTEN", hocsinh.HoTen));
                sqlParams.Add(new SqlParameter("@NGAYSINH", hocsinh.NgaySinh));
                sqlParams.Add(new SqlParameter("@DIACHI", hocsinh.DiaChi));
                sqlParams.Add(new SqlParameter("@DIENTHOAI", hocsinh.DienThoai));
                sqlParams.Add(new SqlParameter("@EMAIL", hocsinh.Email));
                sqlParams.Add(new SqlParameter("@GIOITINH", hocsinh.GioiTinh));
                return SQLDataProvider.ExecuteNoneQuery("sp_ThemHocSinh", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }            
        }

        public static int CapNhatThongTinHocSinh(DTOHocSinh hocsinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAHS", hocsinh.MaHS));
                sqlParams.Add(new SqlParameter("@HOTEN", hocsinh.HoTen));
                sqlParams.Add(new SqlParameter("@NGAYSINH", hocsinh.NgaySinh));
                sqlParams.Add(new SqlParameter("@DIACHI", hocsinh.DiaChi));
                sqlParams.Add(new SqlParameter("@DIENTHOAI", hocsinh.DienThoai));
                sqlParams.Add(new SqlParameter("@EMAIL", hocsinh.Email));
                sqlParams.Add(new SqlParameter("@GIOITINH", hocsinh.GioiTinh));
                return SQLDataProvider.ExecuteNoneQuery("sp_CapNhatHocSinh", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int XoaHocSinh(DTOHocSinh hocsinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAHS", hocsinh.MaHS));
                return SQLDataProvider.ExecuteNoneQuery("sp_XoaHocSinh", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable TraCuuHocSinh(string makhoilop, string malop, DTOHocSinh hocsinh,string gioitinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAHS", hocsinh.MaHS));
                sqlParams.Add(new SqlParameter("@HOTEN", hocsinh.HoTen));
                sqlParams.Add(new SqlParameter("@HO", ""));
                sqlParams.Add(new SqlParameter("@TEN", ""));
                sqlParams.Add(new SqlParameter("@MALOP", malop));
                sqlParams.Add(new SqlParameter("@MAKHOILOP", makhoilop));
                if(gioitinh == "1")
                    sqlParams.Add(new SqlParameter("@GIOITINH", hocsinh.GioiTinh));
                else
                    sqlParams.Add(new SqlParameter("@GIOITINH", ""));
                DataTable dt = SQLDataProvider.ExecuteQuery("sp_TraCuuThongTinHocSinh", sqlParams);
                DataColumn columnChon = new DataColumn("IsCheck", System.Type.GetType("System.Boolean"));
                columnChon.DefaultValue = false;
                dt.Columns.Add(columnChon);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

        public static DataTable TraCuuHocSinh(string makhoilop, string malop, string ho, string ten, DTOHocSinh hocsinh,string gioitinh)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAHS", hocsinh.MaHS));
                sqlParams.Add(new SqlParameter("@HOTEN", ""));
                sqlParams.Add(new SqlParameter("@HO", ho));
                sqlParams.Add(new SqlParameter("@TEN", ten));
                sqlParams.Add(new SqlParameter("@MALOP", malop));
                sqlParams.Add(new SqlParameter("@MAKHOILOP", makhoilop));
                if (gioitinh == "1")
                    sqlParams.Add(new SqlParameter("@GIOITINH", hocsinh.GioiTinh));
                else
                    sqlParams.Add(new SqlParameter("@GIOITINH", ""));
                DataTable dt = SQLDataProvider.ExecuteQuery("sp_TraCuuThongTinHocSinh", sqlParams);
                DataColumn columnChon = new DataColumn("IsCheck", System.Type.GetType("System.Boolean"));
                columnChon.DefaultValue = false;
                dt.Columns.Add(columnChon);
                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static DataTable LietKeLop(object makhoilop)
        {
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@MAKHOILOP", makhoilop.ToString()));
                return SQLDataProvider.ExecuteQuery("sp_TraCuuDanhSachLop", sqlParams);
            }
            catch (Exception ex)
            {
                throw ex;
            }   
        }
    }
}
